/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-07-01     andy       the first version
 */
#ifndef APPLICATIONS_MODBUS485_H_
#define APPLICATIONS_MODBUS485_H_

#include <rtdevice.h>
#include <board.h>

#include <string.h>
//-----------------------------------------------------------
#define RS485_AUTO_DIR_CTRL  0       //1 means RS485 driver has auto direction control function, such as MAX13487E
                                     //MAX485 has no auto direction control function, should not define this macro as 0

#if RS485_AUTO_DIR_CTRL
#define RS485_TXEN_PIN    GET_PIN(E, 15)              //RS485 TXEN, 1=TX 0=RX
#define RS485_TXEN        rt_pin_write(RS485_TXEN_PIN, PIN_HIGH)        //enable rs485 TX
#define RS485_RXEN        rt_pin_write(RS485_TXEN_PIN, PIN_LOW)         //enable rs485 RX
#endif

#define RS485_RX_BUF_LEN        50          //RS485 receive buffer length

#define SOILSENSOR_NUMBR        1           //1个管式土壤温湿度
#define SOILSENSOR_QUERYLEN     8           //RS485查询命令长度


#define RS485_SAMPLE_CYCLE   10000                    //control the cycle of DS18B20 data sampling



//------------RS485--------------

typedef struct {
    //-------sensor-------
    float LV1_soil_temp;                           //土壤温湿度
    float LV1_soil_humi;                           //

    float LV2_soil_temp;                           //土壤温湿度
    float LV2_soil_humi;                           //

    float LV3_soil_temp;                           //土壤温湿度
    float LV3_soil_humi;                           //

    float LV4_soil_temp;                           //土壤温湿度
    float LV4_soil_humi;                           //

}sensor_Data_t;



extern sensor_Data_t  rs485sensor_data;      //RS485总线传感器数据

extern int modbus485_init(void);             //RS485 task initial


#endif /* APPLICATIONS_MODBUS485_H_ */
